home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / omega / otime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-06  |  2.3 KB  |  85 lines

  1. /* omega copyright (c) 1987,1988 by Laurence Raphael Brothers */
  2. /* otime.c */
  3.  
  4. /* this file deals with the passage of time in omega */
  5.  
  6. #include "oglob.h"
  7.  
  8. /* This function coordinates monsters and player actions, as well as
  9. random events. Each tick is a second. There are therefore 60 ticks to
  10. the minute and 60 minutes to the hour.
  11. */
  12.  
  13. void time_clock(reset)
  14. int reset;
  15. {
  16.   pml ml;
  17.  
  18.   if (++Tick > 60) {
  19.     Tick = 0;
  20.     minute_status_check(); /* see about some player statuses each minute */
  21.     if (++Time % 10 == 0) tenminute_check();
  22.   }
  23.   
  24.   if (reset) Tick = (Player.click = 0);
  25.  
  26.   while ((Tick == Player.click) && (Current_Environment != E_COUNTRYSIDE)) {
  27.     if (! gamestatusp(SKIP_PLAYER))
  28.       do {
  29.     resetgamestatus(SKIP_MONSTERS);
  30.     if ((! Player.status[SLEPT])  && 
  31.         (Current_Environment != E_COUNTRYSIDE)) p_process(); 
  32.       } while (gamestatusp(SKIP_MONSTERS) && 
  33.            (Current_Environment != E_COUNTRYSIDE));
  34.     else resetgamestatus(SKIP_PLAYER);
  35.     Player.click = (Player.click + Command_Duration) % 60;
  36.   }
  37.  
  38.   /* klugy but what the heck. w/o this line, if the player caused
  39.   a change-environment to the country, the monsters on the old Level
  40.   will still act, causing all kinds of anomalies and core dumps,
  41.   intermittently. However, any other environment change will reset
  42.   Level appropriately, so only have to check for countryside */
  43.  
  44.   if (Current_Environment != E_COUNTRYSIDE) {
  45.  
  46.     /* no longer search for dead monsters every round -- waste of time.
  47.      Instead, just skip dead monsters. Eventually, the whole level
  48.      will be freed, getting rid of the dead 'uns */
  49.  
  50.     for(ml=Level->mlist;ml!=NULL;ml=ml->next) 
  51.       if (ml->m->hp > 0) {
  52.  
  53.     /* following is a hack until I discover source of phantom monsters */
  54.     if (Level->site[ml->m->x][ml->m->y].creature != ml->m)
  55.       fix_phantom(ml->m); 
  56.  
  57.     if (Tick == ml->m->click) {
  58.       ml->m->click += ml->m->speed;
  59.       while (ml->m->click > 60) ml->m->click -= 60;
  60.       m_pulse(ml->m);
  61.     }
  62.       }
  63.   }
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70. /* remedies occasional defective monsters */
  71. void fix_phantom(m)
  72. struct monster *m;
  73. {
  74.   if (Level->site[m->x][m->y].creature == NULL) {
  75.     mprint("You hear a sound like a sigh of relief....");
  76.     Level->site[m->x][m->y].creature = m;
  77.   }
  78.   else {
  79.     mprint("You hear a puff of displaced air....");
  80.     findspace(&(m->x),&(m->y),-1);
  81.     Level->site[m->x][m->y].creature = m;
  82.     m_death(m);
  83.   }
  84. }
  85.